//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using Mindscape.BackgroundMotion.Core;
using Mindscape.BackgroundMotion.Website.Controllers;
using Mindscape.BackgroundMotion.Website.Controls;

namespace Mindscape.BackgroundMotion.Website.MasterPages
{
  public partial class Default : MasterPage
  {
    public HtmlGenericControl Body
    {
      get
      {
        return BodyTag;
      }
    }

    /// <summary>
    /// Gets or sets a value indicating whether to enable virtual earth integration on this page.
    /// </summary>
    /// <value>
    /// 	<c>true</c> if virtual earth scripts are integrated; otherwise, <c>false</c>.
    /// </value>
    public bool EnableVirtualEarthIntegration
    {
      get { return VEPlaceholder.Visible; }
      set { VEPlaceholder.Visible = value;}
    }

    protected void Page_Load(object sender, EventArgs e)
    {
      // Determine if the current user is a known logged on member and display the login/logout links appropriately
      MembershipController membershipController = new MembershipController();

      if (membershipController.IsLoggedIn)
      {
        LoginLink.NavigateUrl = "~/Logout.aspx";
        LoginLink.Text = "Logout";
        SignupLink.Visible = TopSeparatorLiteral.Visible = false;
      }
      else
      {
        LoginLink.NavigateUrl = "~/Login.aspx";
        LoginLink.Text = "Login";
        SignupLink.NavigateUrl = "~/Signup.aspx";
        SignupLink.Visible = TopSeparatorLiteral.Visible = true;
      }


      // Fetch the tag cloud which should be displayed on the left panel
      ContributionController contributionController = new ContributionController();
      TagCloud.TagCloudData = new TagCloudData(contributionController.GetPopularTags(), 0.9, 0, 1.6);
    }

    /// <summary>
    /// Handles the Click event of the AddFeedbackButton by submitting the feedback 
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void AddFeedbackButton_Click(object sender, EventArgs e)
    {
      IMembershipController membershipController = ServiceLocator.Get<IMembershipController>();
      membershipController.SubmitFeedback(FeedbackText.Text);
    }

    /// <summary>
    /// Handles the Click event of the Search control by redirecting to the search page
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Search_Click(object sender, EventArgs e)
    {
      Response.Redirect(string.Format("~/Search.aspx?q={0}", SearchBox.Text.Trim()));
    }
  }
}